home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / fi.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  17KB  |  711 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                    ATUtilities File Transfer                  ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include "janus.h"
  10. #include "ATUtilities.h"
  11.  
  12. UBYTE *FilePort="ATUtilities File Transfer";
  13. UBYTE *PrefsName="AT:Prefs/FileTransfer.prefs";
  14. UBYTE *HelpName="AT:Help/FileTransfer.help";
  15.  
  16. struct FilePrefs
  17. {
  18.  UWORD Handles;
  19. };
  20.  
  21. struct FilePrefs FilePrefs={150};
  22.  
  23. #define HANDLE_FILE 1
  24. #define HANDLE_LOCK 2
  25.  
  26. #define HANDLE_FREE 0
  27. #define HANDLE_USED 255
  28.  
  29. struct Handle
  30. {
  31.  UBYTE HandleType;
  32.  UBYTE HandleControl;
  33.  APTR  Address;
  34. };
  35.  
  36. struct System
  37. {
  38.  UWORD FreeHandles;
  39.  UWORD UsedHandles;
  40.  UWORD Handles;
  41.  ULONG SystemSize;
  42.  struct Handle Handle[2];
  43. } *Sys;
  44. #define SYSTEM_SIZE(x) (ULONG)(4L+(x*sizeof(struct Handle)))
  45.  
  46. struct NewDateStamp ti;
  47.  
  48. struct DirectoryEntry
  49. {
  50.  UBYTE Name[30];
  51.  ULONG Size;
  52.  UWORD Protection;
  53.  UBYTE EntryType;
  54.  UBYTE Hour;
  55.  UBYTE Minute;
  56.  UBYTE Second;
  57.  UBYTE Day;
  58.  UBYTE Month;
  59.  UWORD Year;
  60. };
  61.  
  62. #define MAX_ENTRIES (PUBLIC_PAGESIZE/sizeof(struct DirectoryEntry))
  63.  
  64. struct Directory
  65. {
  66.  struct DirectoryEntry Entry[];
  67. } *dirword,*dirbyte;
  68.  
  69. struct InfoBlock
  70. {
  71.  ULONG NumSoftErrors;
  72.  ULONG UnitNumber;
  73.  ULONG DiskState;
  74.  ULONG NumBlocks;
  75.  ULONG NumBlocksUsed;
  76.  ULONG BytesPerBlock;
  77.  ULONG DiskType;
  78. } *infoword;
  79.  
  80. struct JanusBase *JanusBase;
  81. struct Library   *GfxBase;
  82. struct Library   *IntuitionBase;
  83. struct Library   *ATUtilitiesBase;
  84.  
  85. struct AppManager   *app;
  86. struct Message      *AppMessage;
  87. struct ExtSetupSig  *ExtSetupSig;
  88. struct Window       *WindowPtr;
  89. struct RastPort     *rp;
  90. struct CommMemory   *jhbyte,*jhword;
  91.  
  92. LONG  JanusSignal;
  93. LONG  PortSignal;
  94. ULONG JanusSignalMask;
  95. ULONG PortSignalMask;
  96. ULONG WaitSignalMask;
  97. ULONG AppSignalMask;
  98. ULONG Signale;
  99.  
  100. VOID  HandleInt();
  101. VOID  ShowInfo();
  102. VOID  OpenAll();
  103. VOID  CloseAll();
  104. BOOL  EinstellungenAendern();
  105. BOOL  Valid();
  106. WORD  AllocHandle();
  107. VOID  FreeHandle();
  108.  
  109. struct MsgPort  *Port;
  110.  
  111.  
  112. /* Installationsroutine */
  113. VOID main()
  114. {
  115.  REGISTER UWORD        i;
  116.  REGISTER BOOL         bool;
  117.  
  118.  OpenAll();
  119.  bool=FALSE;
  120.  while(bool==FALSE)
  121.   {
  122.    Signale=Wait(WaitSignalMask);
  123.    if(Signale & PortSignalMask)
  124.     {
  125.      i=Received(Port);
  126.      switch(i)
  127.       {
  128.        case UTILITY_CALL:
  129.          bool=EinstellungenAendern();
  130.         break;
  131.        case UTILITY_QUIT:
  132.          bool=ExitWarning();
  133.         break;
  134.        case UTILITY_INFO:
  135.          ShowInfo();
  136.         break;
  137.        case UTILITY_HELP:
  138.          Help(HelpName,0);
  139.         break;
  140.       }
  141.     }
  142.    if(Signale & JanusSignalMask)
  143.     {
  144.      HandleInt();
  145.     }
  146.    if(app!=NULL)
  147.     {
  148.      if(Signale & AppSignalMask)
  149.       {
  150.        AppMessage=GetMsg(app->Port);
  151.        if(AppMessage!=NULL)
  152.         {
  153.          ReplyMsg(AppMessage);
  154.          bool=EinstellungenAendern();
  155.         }
  156.       }
  157.     }
  158.   }
  159.  CloseAll();
  160. }
  161.  
  162.  
  163. /* PC-Befehle ausführen */
  164. VOID HandleInt()
  165. {
  166.  ULONG                         *ml;
  167.  REGISTER LONG                  l;
  168.  REGISTER WORD                  i;
  169.  REGISTER BOOL                  bool;
  170.  register struct FileHandle    *fh;
  171.  register struct FileLock      *lock,*lock2;
  172.  register struct FileInfoBlock *fib;
  173.  register struct InfoData      *info;
  174.  
  175.  switch(jhword->Arg1)
  176.   {
  177.    case 1000:
  178.      for(i=0;i<Sys->Handles;i++)
  179.       {
  180.        if((Valid(i,-1))==TRUE)
  181.         {
  182.          switch(Sys->Handle[i].HandleType)
  183.           {
  184.            case HANDLE_FILE:
  185.              Close(Sys->Handle[i].Address);
  186.             break;
  187.            case HANDLE_LOCK:
  188.              UnLock(Sys->Handle[i].Address);
  189.             break;
  190.           }
  191.          FreeHandle(i);
  192.         }
  193.       }
  194.     break;
  195.    case 0:
  196.      switch(jhword->Arg2)
  197.       {
  198.        case 1:
  199.          i=MODE_OLDFILE;
  200.         break;
  201.        case 2:
  202.          i=MODE_NEWFILE;
  203.         break;
  204.        default:
  205.          i=MODE_READWRITE;
  206.         break;
  207.       }
  208.      fh=Open(&jhbyte->Memory,i);
  209.      if(fh!=NULL)
  210.       {
  211.        i=AllocHandle();
  212.        if(i!=-1)
  213.         {
  214.          Sys->Handle[i].Address=fh;
  215.          Sys->Handle[i].HandleType=HANDLE_FILE;
  216.          jhword->Arg2=10000;
  217.          jhword->Arg3=i;
  218.         }
  219.        else
  220.         {
  221.          jhword->Arg2=50;
  222.          Close(fh);
  223.         }
  224.       }
  225.      else
  226.       {
  227.        jhword->Arg2=75;
  228.       }
  229.     break;
  230.    case 1:
  231.      if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
  232.       {
  233.        switch(Sys->Handle[i].HandleType)
  234.         {
  235.          case HANDLE_FILE:
  236.            Close(Sys->Handle[jhword->Arg2].Address);
  237.           break;
  238.         }
  239.        FreeHandle(jhword->Arg2);
  240.       }
  241.     break;
  242.    case 2:
  243.      if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
  244.       {
  245.        jhword->Arg2=Read(Sys->Handle[jhword->Arg2].Address,&jhbyte->Memory,jhword->Arg3);
  246.       } else jhword->Arg2=0;
  247.     break;
  248.    case 3:
  249.      if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
  250.       {
  251.        jhword->Arg2=Write(Sys->Handle[jhword->Arg2].Address,&jhbyte->Memory,jhword->Arg3);
  252.       } else jhword->Arg2=0;
  253.     break;
  254.    case 7:
  255.      if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
  256.       {
  257.        switch(jhword->Arg4)
  258.         {
  259.          case 1:
  260.            i=OFFSET_CURRENT;
  261.           break;
  262.          case 2:
  263.            i=OFFSET_END;
  264.           break;
  265.          default:
  266.            i=OFFSET_BEGINNING;
  267.           break;
  268.         }
  269.        l=Seek(Sys->Handle[jhword->Arg2].Address,jhword->Arg3,i);
  270.        ml=(ULONG *)jhword;
  271.        ml[0]=ConvertIntelMotorola(l);
  272.        jhword->Arg2=10000;
  273.       } else jhword->Arg2=0;
  274.     break;
  275.    case 9:
  276.      i=DeleteFile(&jhbyte->Memory);
  277.      if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
  278.     break;
  279.    case 10:
  280.      jhword->Arg2=IoErr();
  281.     break;
  282.    case 11:
  283.      lock=Lock(&jhbyte->Memory,ACCESS_READ);
  284.      if(lock!=NULL)
  285.       {
  286.        fib=AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR|MEMF_PUBLIC);
  287.        if(fib!=NULL)
  288.         {
  289.          l=0;
  290.          i=Examine(lock,fib);
  291.          while((i!=0) && (l<=MAX_ENTRIES))
  292.           {
  293.            strncpy(&dirbyte->Entry[l].Name,&fib->fib_FileName,30);
  294.            dirword->Entry[l].Protection=(UWORD)fib->fib_Protection;
  295.            if(fib->fib_DirEntryType<0) dirbyte->Entry[l].EntryType=0; else dirbyte->Entry[l].EntryType=1;
  296.            dirword->Entry[l].Size=ConvertIntelMotorola(fib->fib_Size);
  297.            ConvertDateStamp(&fib->fib_Date,&ti);
  298.            dirbyte->Entry[l].Hour=ti.Hour;
  299.            dirbyte->Entry[l].Minute=ti.Minute;
  300.            dirbyte->Entry[l].Second=ti.Second;
  301.            dirbyte->Entry[l].Day=ti.Day;
  302.            dirbyte->Entry[l].Month=ti.Month;
  303.            dirword->Entry[l].Year=ti.Year;
  304.            i=ExNext(lock,fib);
  305.            l++;
  306.           }
  307.          jhword->Arg2=10000;
  308.          jhword->Arg3=l-1;
  309.          FreeMem(fib,sizeof(struct FileInfoBlock));
  310.         }
  311.        else jhword->Arg2=75;
  312.        UnLock(lock);
  313.       }
  314.      else jhword->Arg2=50;
  315.     break;
  316.    case 12:
  317.      lock=Lock(&jhbyte->Memory,ACCESS_READ);
  318.      if(lock!=NULL)
  319.       {
  320.        i=AllocHandle();
  321.        if(i!=-1)
  322.         {
  323.          Sys->Handle[i].Address=lock;
  324.          Sys->Handle[i].HandleType=HANDLE_LOCK;
  325.          jhword->Arg2=10000;
  326.          jhword->Arg3=i;
  327.         }
  328.        else
  329.         {
  330.          jhword->Arg2=50;
  331.          UnLock(lock);
  332.         }
  333.       }
  334.     break;
  335.    case 13:
  336.      if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
  337.       {
  338.        UnLock(Sys->Handle[jhword->Arg2].Address);
  339.        FreeHandle(jhword->Arg2);
  340.       }
  341.     break;
  342.    case 14:
  343.      if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
  344.       {
  345.        lock=Sys->Handle[jhword->Arg2].Address;
  346.        fib=AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR|MEMF_PUBLIC);
  347.        if(fib!=NULL)
  348.         {
  349.          Examine(lock,fib);
  350.          strcpy(&jhbyte->Memory[2000],&fib->fib_FileName);
  351.          lock2=ParentDir(lock);
  352.          if(lock2==NULL)
  353.           {
  354.            strcpy(&jhbyte->Memory,&fib->fib_FileName);
  355.            strcat(&jhbyte->Memory,":");
  356.           }
  357.          while(lock2!=NULL)
  358.           {
  359.            Examine(lock2,fib);
  360.            lock=ParentDir(lock2);
  361.            UnLock(lock2);
  362.            strcpy(&jhbyte->Memory,&fib->fib_FileName);
  363.            if(lock==NULL)
  364.              strcat(&jhbyte->Memory,":");
  365.            else
  366.              strcat(&jhbyte->Memory,"/");
  367.            strcat(&jhbyte->Memory,&jhbyte->Memory[2000]);
  368.            strcpy(&jhbyte->Memory[2000],&jhbyte->Memory);
  369.            lock2=lock;
  370.           }
  371.          FreeMem(fib,sizeof(struct FileInfoBlock));
  372.         }
  373.        jhword->Arg2=10000;
  374.       }
  375.      else jhword->Arg2=50;
  376.     break;
  377.    case 15:
  378.      if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
  379.       {
  380.        lock=Sys->Handle[jhword->Arg2].Address;
  381.        info=AllocMem(sizeof(struct InfoData),MEMF_CLEAR|MEMF_PUBLIC);
  382.        if(info!=NULL)
  383.         {
  384.          Info(lock,info);
  385.          infoword->NumSoftErrors=ConvertIntelMotorola(info->id_NumSoftErrors);
  386.          infoword->UnitNumber=ConvertIntelMotorola(info->id_UnitNumber);
  387.          infoword->DiskState=ConvertIntelMotorola(info->id_DiskState);
  388.          infoword->NumBlocks=ConvertIntelMotorola(info->id_NumBlocks);
  389.          infoword->NumBlocksUsed=ConvertIntelMotorola(info->id_NumBlocksUsed);
  390.          infoword->BytesPerBlock=ConvertIntelMotorola(info->id_BytesPerBlock);
  391.          infoword->DiskType=ConvertIntelMotorola(info->id_DiskType);
  392.          FreeMem(info,sizeof(struct InfoData));
  393.          jhword->Arg2=10000;
  394.         }
  395.        else jhword->Arg2=100;
  396.       }
  397.      else jhword->Arg2=50;
  398.     break;
  399.    case 16:
  400.      lock=Lock(&jhbyte->Memory,ACCESS_READ);
  401.      if(lock!=NULL)
  402.       {
  403.        lock2=CurrentDir(lock);
  404.        jhword->Arg2=10000;
  405.       }
  406.      else jhword->Arg2=50;
  407.     break;
  408.    case 17:
  409.      lock=CreateDir(&jhbyte->Memory);
  410.      if(lock!=NULL)
  411.       {
  412.        UnLock(lock);
  413.        jhword->Arg2=10000;
  414.       }
  415.      else jhword->Arg2=50;
  416.     break;
  417.    case 18:
  418.      i=Rename(&jhbyte->Memory,&jhword->Memory[1000]);
  419.      if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
  420.     break;
  421.    case 19:
  422.      i=Execute(&jhbyte->Memory,NULL,NULL);
  423.      if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
  424.     break;
  425.   }
  426.  SendJanusInt(26);
  427. }
  428.  
  429.  
  430. /* Installationsroutine */
  431. VOID OpenAll()
  432. {
  433.  REGISTER UWORD              i;
  434.  register struct MsgPort    *p;
  435.  register struct FileHandle *fh;
  436.  
  437.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  438.  if(ATUtilitiesBase==NULL)
  439.   {
  440.    printf("FEHLER: Kann ATUtilities-Library nicht öffnen.\n");
  441.    CloseAll();
  442.   }
  443.  
  444.  
  445.  GfxBase=OpenLibrary("graphics.library",0L);
  446.  IntuitionBase=OpenLibrary("intuition.library",0L);
  447.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  448.   {
  449.    CloseAll();
  450.   }
  451.  
  452.  p=FindPort(FilePort);
  453.  if(p!=NULL)
  454.   {
  455.    InfoRequest("ATUtilities File Transfer ist schon aktiv.");
  456.    CloseAll();
  457.   }
  458.  
  459.  JanusBase=OpenLibrary("janus.library",0L);
  460.  if(JanusBase==NULL)
  461.   {
  462.    ErrorRequest(ERROR_JANUS);
  463.    CloseAll();
  464.   }
  465.  
  466.  Port=CreatePort(FilePort,0L);
  467.  if(Port==NULL)
  468.   {
  469.    ErrorRequest(ERROR_MPORT);
  470.    CloseAll();
  471.   }
  472.  
  473.  fh=Open(PrefsName,MODE_OLDFILE);
  474.  if(fh!=NULL)
  475.   {
  476.    Read(fh,&FilePrefs,sizeof(struct FilePrefs));
  477.    Close(fh);
  478.   }
  479.  
  480.  Sys=AllocMem(SYSTEM_SIZE(FilePrefs.Handles),MEMF_CLEAR|MEMF_PUBLIC);
  481.  if(Sys==NULL)
  482.   {
  483.    ErrorRequest(ERROR_ALLOC);
  484.    CloseAll();
  485.   }
  486.  Sys->Handles=FilePrefs.Handles;
  487.  Sys->SystemSize=SYSTEM_SIZE(Sys->Handles);
  488.  Sys->FreeHandles=Sys->Handles;
  489.  
  490.  ExtSetupSig=CreatePublicHandler(26);
  491.  if(ExtSetupSig==NULL)
  492.   {
  493.    CloseAll();
  494.   }
  495.  
  496.  app=CreateAppItem("ATUtilities File Transfer");
  497.  if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
  498.  
  499.  jhword=ExtSetupSig->WordAccess;
  500.  jhbyte=ExtSetupSig->ByteAccess;
  501.  dirword=infoword=jhword;
  502.  dirbyte=jhbyte;
  503.  PortSignal=Port->mp_SigBit;
  504.  PortSignalMask=(1L<<PortSignal);
  505.  JanusSignal=ExtSetupSig->JanusSignal;
  506.  JanusSignalMask=ExtSetupSig->JanusSignalMask;
  507.  WaitSignalMask=PortSignalMask+JanusSignalMask+AppSignalMask;
  508.  ChangeTaskPri(10);
  509. }
  510.  
  511.  
  512. /* Programmende */
  513. VOID CloseAll()
  514. {
  515.  if(app) DeleteAppItem(app);
  516.  if(Sys) FreeMem(Sys,Sys->SystemSize);
  517.  if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
  518.  if(Port) DeletePort(Port);
  519.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  520.  if(GfxBase) CloseLibrary(GfxBase);
  521.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  522.  if(JanusBase) CloseLibrary(JanusBase);
  523.  exit(0);
  524. }
  525.  
  526.  
  527. /* Einstellungsfenster */
  528. BOOL EinstellungenAendern()
  529. {
  530.  UBYTE                         tex[50];
  531.  REGISTER BOOL                 bool,ende;
  532.  REGISTER ULONG                Class;
  533.  REGISTER UBYTE               *integer;
  534.  register struct Window       *win;
  535.  register struct Gadget       *t1,*t2,*gad;
  536.  register struct IntuiMessage *msg;
  537.  register struct FileHandle   *fh;
  538.  register struct RastPort     *rp;
  539.  register struct TextFont     *opal;
  540.  
  541.  bool=FALSE;
  542.  win=CreateStdWindow("ATUtilities - File Transfer Einstellungen",
  543.                      75,75,450,72+BorderHeight(),GADGETUP|CLOSEWINDOW,
  544.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE|GIMMEZEROZERO);
  545.  if(win!=NULL)
  546.   {
  547.    rp=win->RPort;
  548.    opal=GetOpalFont();
  549.    SetFont(rp,opal);
  550.    CreateBoolGadget(win,10,5,155,12,"Einstellungen okay",1);
  551.    CreateBoolGadget(win,170,5,155,12,"Programm beenden",2);
  552.    CreateBoolGadget(win,335,5,50,12,"Info",3);
  553.    CreateBoolGadget(win,390,5,50,12,"Hilfe",4);
  554.    sprintf(&tex,"%ld",FilePrefs.Handles);
  555.    integer=CreateIntegerGadget(win,390,24,50,12,&tex,5,5);
  556.    SelectStdFPen(rp);
  557.    WriteText(rp,20,33,"Maximale Anzahl von Locks und Dateien:");
  558.    sprintf(&tex,"Aktuelle Anzahl von Handles: %ld",Sys->Handles);
  559.    WriteText(rp,20,45,&tex);
  560.    sprintf(&tex,"Aktuelle Anzahl freier Handles: %ld",Sys->FreeHandles);
  561.    WriteText(rp,20,55,&tex);
  562.    sprintf(&tex,"Aktuelle Anzahl belegter Handles: %ld",Sys->UsedHandles);
  563.    WriteText(rp,20,65,&tex);
  564.    ende=FALSE;
  565.    while(ende==FALSE)
  566.     {
  567.      WaitPort(win->UserPort);
  568.      msg=GetMsg(win->UserPort);
  569.      gad=msg->IAddress;
  570.      Class=msg->Class;
  571.      ReplyMsg(msg);
  572.      switch(Class)
  573.       {
  574.        case CLOSEWINDOW:
  575.          ende=TRUE;
  576.         break;
  577.        case GADGETUP:
  578.          switch(gad->GadgetID)
  579.           {
  580.            case 1:
  581.              FilePrefs.Handles=atol(integer);
  582.              if(FilePrefs.Handles<10) FilePrefs.Handles=10;
  583.              fh=Open(PrefsName,MODE_NEWFILE);
  584.              if(fh!=NULL)
  585.               {
  586.                Write(fh,&FilePrefs,sizeof(struct FilePrefs));
  587.                Close(fh);
  588.               }
  589.              ende=TRUE; bool=FALSE;
  590.             break;
  591.            case 2:
  592.              ende=TRUE; bool=TRUE;
  593.             break;
  594.            case 3:
  595.              ShowInfo();
  596.             break;
  597.            case 4:
  598.              Help(HelpName,0);
  599.             break;
  600.           }
  601.         break;
  602.       }
  603.     }
  604.    DeleteStdWindow(win);
  605.   }
  606.  if(bool==TRUE) bool=ExitWarning();
  607.  return(bool);
  608. }
  609.  
  610.  
  611. /* Information */
  612. struct InfoItem ii1=
  613. {
  614.  0,0
  615. };
  616.  
  617. struct InfoItem ii2=
  618. {
  619.  1,1,
  620.  "Service",
  621.  "Haben Sie Anregungen oder",
  622.  "Verbesserungswünsche?",
  623.  "",
  624.  "Senden Sie eine PM (Persönliche Mitteilung)",
  625.  "an T.DREIBHOLZ in folgenden Mailboxen:",
  626.  "",
  627.  "Carrier: 02261/75835",
  628.  "Apogee: 02262/68614",
  629.  "",
  630.  "oder schreiben Sie an:",
  631.  "",
  632.  "Thomas Dreibholz",
  633.  "Molbachweg 7",
  634.  "D-51674 Wiehl"
  635. };
  636.  
  637. struct Info info=
  638. {
  639.  2,
  640.  &ii1,
  641.  &ii2
  642. };
  643.  
  644. VOID ShowInfo()
  645. {
  646.  ExtInformationBox(NULL,
  647.                    "ATUtilities File Transfer - Information",
  648.                    "$VER: File Transfer - Version 4.0",
  649.                    "Copyright (C) 1992-1994 by",
  650.                    "Thomas Dreibholz",
  651.                    "All rights reserved.",
  652.                    "AT:Icons/Utility",&info);
  653. }
  654.  
  655.  
  656. /* Handle belegen */
  657. WORD AllocHandle()
  658. {
  659.  REGISTER UWORD i;
  660.  
  661.  if(Sys->FreeHandles>0)
  662.   {
  663.    for(i=0;i<Sys->Handles;i++)
  664.     {
  665.      if(Sys->Handle[i].HandleControl==HANDLE_FREE)
  666.       {
  667.        Sys->Handle[i].HandleControl=HANDLE_USED;
  668.        Sys->UsedHandles++;
  669.        Sys->FreeHandles--;
  670.        return(i);
  671.       }
  672.     }
  673.   }
  674.  return(-1);
  675. }
  676.  
  677.  
  678. /* Handle freigeben */
  679. VOID FreeHandle(num)
  680.  UWORD num;
  681. {
  682.  Sys->Handle[num].HandleControl=HANDLE_FREE;
  683.  Sys->UsedHandles--;
  684.  Sys->FreeHandles++;
  685. }
  686.  
  687.  
  688. /* Prüfe Gültigkeit von Handle */
  689. BOOL Valid(num,typ)
  690.  UWORD num;
  691.  WORD  typ;
  692. {
  693.  if((num<Sys->Handles) && (Sys->Handle[num].HandleControl==HANDLE_USED))
  694.   {
  695.    if(typ==-1) return(TRUE);
  696.    if(Sys->Handle[num].HandleType==(UBYTE)typ) return(TRUE);
  697.   }
  698.  return(FALSE);
  699. }
  700.  
  701.  
  702. /* Umwandung Intel <-> Motorola von Longwords */
  703. #asm
  704.    public _ConvertIntelMotorola
  705. _ConvertIntelMotorola:
  706.    move.l 4(sp),d0
  707.    swap d0
  708.    rts
  709. #endasm
  710.  
  711.